package cn.iotab.iotkit.transport.api.access.model.message;


import cn.iotab.iotkit.transport.api.access.model.custom.ProtocolConstant;
import com.alibaba.fastjson.JSONObject;

import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;


/**
 * 设备消息回复
 *
 * @author zhouhao
 * @since 1.0.0
 */
public interface DeviceMessageReply extends Message {

    OriginMessageReply toOriginMessageReply();

    //业务码,具体由设备定义
    @Nullable
    Integer getCode();

    void setCode(Integer code);
    //错误消息
    @Nullable
    String getErrorMsg();

    //响应内容
    JSONObject getData();

    default void setSuccess(){
        setCode(ProtocolConstant.CODE_SUCCESS);
    }
    //是否成功
    default boolean isSuccess() {
        return ProtocolConstant.CODE_SUCCESS.equals(getCode());
    }


    //根据另外的消息填充对应属性
    DeviceMessageReply from(@NotNull DeviceMessage message);

}
